var SweetAlert = function () {
	
	var setSweetAlertEvents = function() {
		$('.mt-sweetalert').each(function(){
    		var sa_title = $(this).data('title');
    		var sa_message = $(this).data('message');
    		var sa_type = $(this).data('type');	
    		var sa_allowOutsideClick = $(this).data('allow-outside-click');
    		var sa_showConfirmButton = $(this).data('show-confirm-button');
    		var sa_showCancelButton = $(this).data('show-cancel-button');
    		var sa_closeOnConfirm = $(this).data('close-on-confirm');
    		var sa_closeOnCancel = $(this).data('close-on-cancel');
    		var sa_confirmButtonText = $(this).data('confirm-button-text');
    		var sa_cancelButtonText = $(this).data('cancel-button-text');
    		var sa_popupTitleSuccess = $(this).data('popup-title-success');
    		var sa_popupMessageSuccess = $(this).data('popup-message-success');
    		var sa_popupTitleCancel = $(this).data('popup-title-cancel');
    		var sa_popupMessageCancel = $(this).data('popup-message-cancel');
    		var sa_confirmButtonClass = $(this).data('confirm-button-class');
    		var sa_cancelButtonClass = $(this).data('cancel-button-class');
    	
    		$(this).click(function(){
    			//console.log(sa_btnClass);
    			swal({
				  title: sa_title,
				  text: sa_message,
				  type: sa_type,
				  allowOutsideClick: sa_allowOutsideClick,
				  showConfirmButton: sa_showConfirmButton,
				  showCancelButton: sa_showCancelButton,
				  confirmButtonClass: sa_confirmButtonClass,
				  cancelButtonClass: sa_cancelButtonClass,
				  closeOnConfirm: sa_closeOnConfirm,
				  closeOnCancel: sa_closeOnCancel,
				  confirmButtonText: sa_confirmButtonText,
				  cancelButtonText: sa_cancelButtonText,
				},
				function(isConfirm){
			        if (isConfirm){
			        	swal(sa_popupTitleSuccess, sa_popupMessageSuccess, "success");
			        } else {
						swal(sa_popupTitleCancel, sa_popupMessageCancel, "error");
			        }
				});
    		});
    	});
	}

    return {
        //main function to initiate the module
        init: function () {
        	setSweetAlertEvents();
//        	vvv();
    	},
    	
    	success: function (msg){
    		swal({
  			  title: "成功",
  			  text: msg,
  			  type: "success",
  			  confirmButtonClass: "btn-success"
  			});
    	},
    	
    	info: function (msg){
    		swal({
  			  title: "消息",
  			  text: msg,
  			  type: "info",
  			  confirmButtonClass: "btn-info "
  			});
    	},
    	
    	warning: function (msg){
    		swal({
  			  title: "提醒",
  			  text: msg,
  			  type: "warning",
  			  confirmButtonClass: "btn-warning "
  			});
    	},
    	
    	error: function (msg){
    		swal({
    			  title: "失败",
    			  text: msg,
    			  type: "error",
    			  confirmButtonClass: "btn-danger"
    			});
    	},
    	
    	errorSessionExpire: function (){
    		swal({
    			  title: "失败",
    			  text: "您的登录信息已过期，请重新登录",
    			  type: "error",
    			  confirmButtonClass: "btn-danger"
          	}, function(isConfirm) {
    				if (isConfirm) {
    					window.location = $("#hdnContextPath").val() + "/login.action";
    				}
    			});
    	},
    	
    	userRegistSuccess: function (){
    		swal({
    			  title: "成功",
    			  text: "注册成功",
    			  type: "success",
    			  confirmButtonClass: "btn-success"
          	}, function(isConfirm) {
    				if (isConfirm) {
    					window.location = $("#hdnContextPath").val() + "/center.action";
    				}
    			});
    	},
    	
    	userResetPwdSuccess: function (){
    		swal({
    			  title: "成功",
    			  text: "新密码重置成功，请重新登录...",
    			  type: "success",
    			  confirmButtonClass: "btn-success"
          	}, function(isConfirm) {
    				if (isConfirm) {
    					window.location = $("#hdnContextPath").val() + "/login.action";
    				}
    			});
    	},
    	
    	userFaceImageUploadSuccess: function (){
    		swal({
    			  title: "成功",
    			  text: "图片上传成功",
    			  type: "success",
    			  confirmButtonClass: "btn-success"
          	}, function(isConfirm) {
    				if (isConfirm) {
    					window.location = $("#hdnContextPath").val() + "/center.action";
    				}
    			});
    	},
    	
    	resetPwdToLogin: function (){
    		swal({
    			  title: "成功",
    			  text: "密码重置成功！请重新登录.",
    			  type: "success",
    			  confirmButtonClass: "btn-success"
          	}, function(isConfirm) {
    				if (isConfirm) {
    					window.location.reload();
    				}
    			});
    	},
    	
    	// 门户页面上的部分功能需要登录才可以继续
    	uNeedLogin: function (url){
    		swal({
  			  title: "",
  			  text: "请登录后操作",
  			  type: "info",
  			  confirmButtonClass: "btn-info"
        	}, function(isConfirm) {
  				if (isConfirm) {
  					window.location = $("#hdnContextPath").val() + "/login.action?redirectUrl=" + url;
  				}
  			});
    	}
    	
    }

}();

jQuery(document).ready(function() {
    SweetAlert.init();
});
